package com.example.demo;


import com.example.demo.utils.Utils;
import com.example.demo.utils.WangyiUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;

//登微博的的
public class Weibo {
    public static void main(String[] args) throws Exception {
//        Utils.savecokie("https://weibo.com/", "weibo.txt");
        System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_content_setting_values.images", 2);
        prefs.put("download.default_directory", "D:\\");
        options.setExperimentalOption("prefs", prefs);
        ChromeDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://weibo.com/");
        Utils.read(webDriver, "weibo.txt");

        Utils.avoidXpathelementnotfindexception(webDriver, "//*[@id=\"pl_login_form\"]/div/div[3]/div[2]/div/input");
        WebElement elementByXPath = webDriver.findElementByXPath("//*[@id=\"loginname\"]");
        elementByXPath.clear();
        elementByXPath.sendKeys("17549206538");
        webDriver.findElementByXPath("//*[@id=\"pl_login_form\"]/div/div[3]/div[2]/div/input").sendKeys("maw282814...");
        webDriver.findElementByXPath("//*[@id=\"pl_login_form\"]/div/div[3]/div[6]/a").click();

        WebElement webElementda = Utils.avoidCsselementnotfindexception(webDriver, "div[pagenum].WB_feed");
        WebElement element = webElementda.findElement(By.cssSelector("(div[tbinfo].WB_cardwrap)[2]"));
        System.out.println(element.getText());

    }


}
